home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / PrinterClassDriver / PrinterClassDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  8.0 KB  |  279 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        PrinterClassDriver.h
  3.  
  4.     Contains:    structures for PrinterClass
  5.  
  6.     Version:    
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11. #ifndef __PRINTERCLASSDRIVERH__
  12. #define __PRINTERCLASSDRIVERH__
  13.  
  14. #include <MacTypes.h>
  15. #include <Devices.h>
  16. #include <DriverServices.h>
  17. #include <Processes.h>
  18.  
  19. #ifndef __MIXEDMODE__
  20. #include <mixedmode.h>
  21. #endif
  22.  
  23. #include <USB.h>
  24.  
  25. #if DEBUG
  26. #define IF_DEBUG(x)    x
  27. #else
  28. #define IF_DEBUG(x)
  29. #endif
  30.  
  31. #define kCStrPrinterDriverName    "USB Printing Support: "
  32. #define kPStrPrinterDriverName    "\pUSB Printing Support: "
  33. void DriverEntry(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  34. void ExpertNotify(void *exNote);
  35.  
  36. #define kPrinterRetryCount    5
  37.  
  38. /* Move to sys files */
  39. #define kUSBPrintClass 7
  40. #define kUSBPrintSubClass 1
  41.  
  42. #define TRANSFER_SIZE    4096 /* ideally this is the same as VM page size */
  43.  
  44. // section 5.3 USB Device Class Definition for Printing Devices
  45. enum {
  46.     kUSBPrintClassGetDeviceID = 0,
  47.     kUSBPrintClassGetCentronicsStatus = 1,
  48.     kUSBPrintClassSoftReset = 2,
  49.     kUSBPrintClassProtocolReserved = 0,
  50.     kUSBPrintClassProtocolUnidirectional = 1,
  51.     kUSBPrintClassProtocolBidirectional = 2,
  52.     // 3..0xFE reserved for future use
  53.     kUSBPrintClassProtocolVendor = 0xFF
  54. };
  55.  
  56. enum 
  57. {
  58.     kDrvrCentronicsStatus = 3,
  59.     kDrvr1284IdString = 4,
  60.     kDrvrNumDevices = 5,
  61.     kDrvrSoftReset = 6,
  62.     kDrvrPrivateSetStorage = 128,
  63.     kDrvrPrivateLog = 129,
  64.     kDrvrPrivateOpnClose = 130
  65. };
  66.  
  67. enum driverstages
  68. {
  69.     kUndefined = 0,
  70.     kNilCompletion,
  71.     kFindInterface_bidirectional,
  72.     kFindInterface_unidirectional,
  73.     kOpenDevice,
  74.     kNewInterfaceRef,
  75.     kSetInterface,
  76.     kConfigureInterface,
  77.     kGetCapabilityString,
  78.     kDelayGetCapability,
  79.     kAllocateCapabilityMem,
  80.     kGetFullCapabilityString,
  81.     kGetInterface,
  82.     kFindBulkOutPipe,
  83.     kFindBulkInPipe,
  84.     kTaskTimeRequired,
  85.  
  86.     kGetCentronicsStatus,
  87.     kDelayGetCentronicsStatus,
  88.     
  89.     kDeallocateCapbilityString,
  90.  
  91.     kReturnFromDriver = 0x1000,
  92.     kRetryTransaction = 0x2000,
  93.     kTransactionPending = 0x8000
  94. };
  95.  
  96. enum {
  97.     uppIODoneProcInfo = kRegisterBased
  98.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  99.          | REGISTER_RESULT_LOCATION(kRegisterD0)
  100.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
  101.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(IOParamPtr)))
  102.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA1, SIZE_CODE(sizeof(DCtlHandle))),
  103.  
  104.     uppQueueUSBReadProcInfo = kCStackBased
  105.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  106.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  107.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  108.  
  109.     uppQueueUSBWriteProcInfo = kCStackBased
  110.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  111.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  112.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  113.  
  114.     uppAbortProcInfo = kCStackBased
  115.          | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
  116.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DriverRefNum)))
  117.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  118.  
  119.     uppControlStatusProcInfo = kCStackBased
  120.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  121.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  122.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *)))
  123. };
  124.  
  125. #if GENERATINGCFM
  126. typedef UniversalProcPtr    QueueUSBReadUPP;
  127. typedef UniversalProcPtr    QueueUSBWriteUPP;
  128. typedef UniversalProcPtr    IODoneUPP;
  129. typedef UniversalProcPtr    AbortUPP;
  130. typedef UniversalProcPtr    ControlStatusUPP;
  131. #else
  132. typedef ProcPtr                QueueUSBReadUPP;
  133. typedef ProcPtr                QueueUSBWriteUPP;
  134. typedef ProcPtr                IODoneUPP;
  135. typedef ProcPtr                AbortUPP;
  136. typedef ProcPtr                ControlStatusUPP;
  137. #endif
  138.  
  139. typedef struct {
  140.     OSErr        err;
  141.     IOParamPtr    pb;
  142.     DCtlPtr        ctl;
  143. } DrvrParams;
  144.  
  145. typedef union {
  146.     char            b;
  147.     struct {
  148.         unsigned    reserved0:2;
  149.         unsigned    paperError:1;
  150.         unsigned    select:1;
  151.         unsigned    notError:1;
  152.         unsigned    reserved1:3;
  153.     } status;
  154. } CentronicsStatusByte;
  155.  
  156. typedef struct usbPrinterPBStruct
  157. {
  158.     //
  159.     //    note: first element must be USBPB pb
  160.     //        since we often cast it to usbPrinterPBStruct
  161.     //
  162.     USBPB                             pb,                    // configuration block
  163.                                     out,                // map client write
  164.                                     in;                    // map client read
  165.     //
  166.     //    optional bulk in pipe
  167.     //
  168.     USBEndPointDescriptorPtr        readDescriptor;        // configuration/interface info
  169.     USBPipeRef                         readPipeRef;        // USB pipe reference
  170.     QueueUSBReadUPP                    qread,                // queue USB read from 68K
  171.                                     r;
  172.     RoutineDescriptor                qreadRD;            // static descriptor
  173.     DrvrParams                        readDrvr;            // currently active read
  174.     int                                readRetryCount;        // retry transactions
  175.     OSStatus                        readStatus;
  176.     
  177.     //
  178.     //    mandatory bulk out pipe
  179.     //
  180.     USBEndPointDescriptorPtr        writeDescriptor;    // configuration/interface info
  181.     USBPipeRef                         writePipeRef;        // USB pipe reference
  182.     QueueUSBWriteUPP                qwrite,                // queue USB write from 68K
  183.                                     w;
  184.     RoutineDescriptor                qwriteRD;            // static descriptor
  185.     DrvrParams                        writeDrvr;            // currently active read
  186.     int                                writeRetryCount;    // retry transactions
  187.     OSStatus                        writeStatus;
  188.     
  189.     //
  190.     //    abort/cancel transactions
  191.     //
  192.     AbortUPP                        qabort,                // cancel from 68K DRVR
  193.                                     a;
  194.     RoutineDescriptor                qabortRD;            // static descriptor
  195.     //
  196.     //    status transactions
  197.     //
  198.     ControlStatusUPP                qstatus,            // simple status from 68K DRVR
  199.                                     s;
  200.     RoutineDescriptor                qstatusRD;            // static descriptor
  201.     DrvrParams                        statusDrvr;            // currently active status request
  202.     //
  203.     //    unit table driver names and refNums
  204.     //
  205.     DRVRHeaderHandle                hDrvr;                // detached from class driver resource file
  206.     DriverRefNum                    outRefNum;            // write unit table ref
  207.     DriverRefNum                    inRefNum;            // read unit table ref
  208.     Str255                            driverOutName;        // write driver name in unit table
  209.     Str255                            driverInName;        // read driver name in unit table
  210.     //
  211.     //    device: configuration and interface details
  212.     //
  213.     UInt8                            terminating;        // offline USS-720 device
  214.     USBDeviceRef                    deviceRef;            // USB device reference
  215.  
  216.     USBDeviceDescriptor                deviceDescriptor;
  217.     USBInterfaceDescriptorPtr        pInterfaceDescriptor;
  218.     UInt32                            interfaceOffset;    // result/param for USB calls
  219.     UInt8                            whichAltInterface;
  220.  
  221.     Str255                            devclass;            // printer class in name registry
  222.     Str255                            model;                // printer model in name registry
  223.     Str255                            name;                // printer name in name registry
  224.  
  225.     unsigned char                    *pCapabilityString;    // 1284 capability string
  226.     USBConfigurationDescriptorPtr    config;                // USB configuration string
  227.  
  228.     unsigned char                    capability[256];    // capability: try not to fragment storage
  229.     unsigned char                    configuration[256];    // configuration: try not to fragment storage
  230.  
  231.     CentronicsStatusByte            centronics;
  232.     //
  233.     //    we double-buffer i/o requests into our heap, using page aligned blocks
  234.     //
  235.     UInt32                            pageWriteAlignedBufferSize,
  236.                                     pageReadAlignedBufferSize;
  237.     UInt8                            *pageWriteAlignedBuffer,
  238.                                     *pageReadAlignedBuffer,
  239.                                     malignedBuffer[ 3*TRANSFER_SIZE ];    //PrintDriverEntry assumes 3*TRANSFER_SIZE
  240.  
  241.     //
  242.     //    class driver async transactions
  243.     //
  244.     SInt32                            transDepth;            // don't nest transactions
  245.     SInt32                             retryCount;            // automatically retry transactions
  246.  
  247.     USBReference                    interfaceRef;
  248.  
  249.     
  250.     UInt32                            configurationNumber;
  251.     UInt32                            interfaceNumber;
  252.     UInt32                            printerProtocol;
  253.     UInt32                            alternateSetting;
  254.     UInt32                            pipeCount;
  255.     
  256.     Boolean                            delayInProgress;
  257.     Boolean                            printerConfigured;
  258.     Boolean                            printerRegistered;
  259.     
  260. };  
  261.  
  262.    
  263. OSStatus OpenBulkEndpoint(struct usbPrinterPBStruct    *pPrinterPB, UInt32    refCon);
  264. OSStatus Abort( DriverRefNum refNum, struct usbPrinterPBStruct *pPrinterPB );
  265. void     ControlStatusRequests( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  266. void     QueueRead( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  267. void     QueueWrite( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  268.  
  269. void      PrintDriverEntry(USBDeviceRef deviceRef, USBDeviceDescriptorPtr desc, USBInterfaceDescriptorPtr pInterface, UInt32 interfaceNumber);
  270.  
  271. OSStatus PrinterRemovalNotification( void );
  272.  
  273. void    hexstr( long count, char *p, char *q );
  274.  
  275. void     ForceUpperStr(char *s);
  276. void     MakeNameRegistrySafeStr(char *s);
  277.  
  278.  
  279. #endif //__PRINTERCLASSDRIVERH__